<script runat="server">
Dim strMessage = ""
Sub Button1_Click(ByVal Source As Object, ByVal e As EventArgs)
     saveFiles()
End Sub
Function saveFiles() As String
	 Dim strFileName As String
	 Dim objFile As HttpPostedFile
	 Dim i As Integer	
	 Dim PathFile as string
	 Dim RealFile as string
	 For  i = 0 To Request.Files.Count- 1  Step  i + 1	 
	 	objFile = Request.Files(i)
		If objFile.FileName <> "" Then			
			PathFile =	"C:\Inetpub\wwwroot\myaspx\photos\"					
			strFileName = objFile.FileName
			strFileName = strFileName.Substring(strFileName.LastIndexOf("\\")+1)
			Dim validstr=" gif,jpg,jnp,bmp"
			if validstr.indexOf(strFileName.Substring(strFileName.LastIndexOf(".")+1))>0 then 
				Try	
					if instrRev(strFileName,"\")>0 then  
						strFileName = mid(strFileName,instrRev(strFileName,"\")+1)
					end if
					RealFile = pathFile &  "_" & strFileName
					objFile.SaveAs(RealFile)
					strMessage+= "Uploaded: d:\\upload\\"
					strMessage+=RealFile+"<br>"
				Catch err As Exception
					strMessage+= "Failed uploading "
					strMessage+=RealFile+": "
					strMessage+=err.ToString()+"<br>"
				End Try
			end if		
		End If
	 Next
End Function
</script>
<html>
<head>
<title>Upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">

<table width="100%">
  
  <%if strMessage = "" then%>
  <tr valign="top"> 
    <td>Upload Photo</td>
    <td >&nbsp;</td>
  </tr>
  <tr valign="top"> 
    <td colspan="2"  >Please upload your 
	photo with size 
	<font color="#FF0000">
	  Width: 80px and Heigh: 100px.
	  </font><br>
      .jnp, .jpg, .gif, .bmp are valid images.<br>
    </td>
  </tr>
  <form id="frmUp" enctype="multipart/form-data" runat="server">
  <tr valign="top"> 
    <td  >Your Photo</td>
    <td > 
      <input class=textbox id="txtFile"  
	  type="file" runat="server" name="file">
      <br>
    </td>
  </tr>
  <tr> 
    <td class=row_white width="30%">&nbsp;</td>
    <td class=row_white width="70%" > <br>
      <input type=button id="Button1" 
	  value="Upload" class=button 
	  onserverclick="Button1_Click" 
	  runat="server" name="button">
      <input type="button" value="Cancel" 
	  onClick="window.close()" 
	  name="button"  class=button>
    </td>
  </tr>
  </form>
  <%else%>
  <tr> 
    <td class=row_white colspan=2 align=center > 
      <p><b><br>
        <br>
        <font color="#0066CC" size="3">Your Photo has been uploaded ! </font></b></p>
      <p><font color="#0066CC"><b>Thank you for using our services.</b></font></p>
    </td>
  </tr>
  <%end if%>
</table>

</body>
</html>
